﻿using System;
using NUnit.Framework;

namespace NJabber.Client
{
    [TestFixture]
    public class RuntimeFactoryTests
    {
        private StandartClientRuntimeFactory factory;

        [SetUp]
        public void SetUp()
        {
            factory = new StandartClientRuntimeFactory();
        }

        [Test]
        public void CreateRuntime_ReturnsNotNullReference()
        {
            ValidateNotNullValue(runtime => runtime);
        }

        [Test]
        public void CreateRuntime_CreatesRuntimeWithRosterCache()
        {
            ValidateNotNullValue(runtime => runtime.RosterCache);
        }

        [Test]
        public void CreateRuntime_CreatesRuntimeWithMessageStanzaFactory()
        {
            ValidateNotNullValue(runtime => runtime.MessageStanzaFactory);
        }

        [Test]
        public void CreateRuntime_CreatesRuntimeWithPresenceStanzaFactory()
        {
            ValidateNotNullValue(runtime => runtime.PresenceStanzaFactory);
        }

        [Test]
        public void CreateRuntime_CreatesRuntimeWithRosterStanzaFactory()
        {
            ValidateNotNullValue(runtime => runtime.RosterStanzaFactory);
        }

        [Test]
        public void CreateRuntime_CreatesSubscriptionStanzaFactory()
        {
            ValidateNotNullValue(runtime => runtime.SubscriptionStanzaFactory);
        }

        [Test]
        public void CreateRuntime_CreatesRuntimeWithPresenceStatusProvider()
        {
            ValidateNotNullValue(runtime => runtime.PresenceStatusProvider);
        }

        [Test]
        public void CreateRuntime_CreatesRuntimeWithPresenceStatusUpdater()
        {
            ValidateNotNullValue(runtime => runtime.PresenceStatusUpdater);
        }

        [Test]
        public void CreateRuntime_CreatesRuntimeWithSubscriptionRegistry()
        {
            ValidateNotNullValue(runtime => runtime.SubscriptionRegistry);
        }

        [Test]
        public void CreateRuntime_CreatesRuntimeWithConnection()
        {
            ValidateNotNullValue(runtime => runtime.Connection);
        }

        private void ValidateNotNullValue(Func<XmppClientRuntime, object> func)
        {
            XmppClientRuntime runtime = factory.CreateRuntime();
            Assert.That(func(runtime), Is.Not.Null);
        }

        [Test]
        public void CreateRuntime_CreatesHandlers()
        {
            XmppClientRuntime runtime = factory.CreateRuntime();
            CollectionAssert.IsNotEmpty(runtime.StanzaHandlers);
        }
    }
}
